#!/bin/sh

set -e

export TIME_ID=`date +%s`

# 变更部署id

find /usr/share/nginx/html -name '*.js' -not -path "*/packages/*" -not -path "*/lib/*" | xargs sed -i "s BUILD_PACKAGE_PUBLIC_URL $BUILD_PACKAGE_PUBLIC_URL g"

find /usr/share/nginx/html -name '*.js' -not -path "*/packages/*" -not -path "*/lib/*" | xargs sed -i "s BUILD_BUILD_ENV_ID $TIME_ID g"
find /usr/share/nginx/html -name '*.html' -not -path "*/packages/*" -not -path "*/lib/*" | xargs sed -i "s BUILD_BUILD_ENV_ID $TIME_ID g"
sed -i "s BUILD_BUILD_ENV_ID $TIME_ID g" /usr/share/nginx/html/packages/microConfig.json
# find /usr/share/nginx/html -name '*.js' -not -path "*/packages/*" -not -path "*/lib/*" | xargs sed -i "s BUILD_BASE_PATH $BUILD_BASE_PATH g"
find /usr/share/nginx/html -name '*.js' -not -path "*/packages/*" -not -path "*/lib/*" | xargs sed -i "s BUILD_API_HOST $BUILD_API_HOST g"
# find /usr/share/nginx/html -name '*.js' -not -path "*/packages/*" -not -path "*/lib/*" | xargs sed -i "s /BUILD_PUBLIC_URL/ ${BUILD_PUBLIC_URL:-/} g"
# find /usr/share/nginx/html -name '*.html' -not -path "*/packages/*" -not -path "*/lib/*" | xargs sed -i "s /BUILD_PUBLIC_URL/ ${BUILD_PUBLIC_URL:-/} g"
# find /usr/share/nginx/html -name '*.css' -not -path "*/packages/*" -not -path "*/lib/*" | xargs sed -i "s /BUILD_PUBLIC_URL/ ${BUILD_PUBLIC_URL:-/} g"
find /usr/share/nginx/html -name '*.js' -not -path "*/packages/*" -not -path "*/lib/*" | xargs sed -i "s BUILD_CLIENT_ID $BUILD_CLIENT_ID g"
find /usr/share/nginx/html -name '*.js' -not -path "*/packages/*" -not -path "*/lib/*" | xargs sed -i "s BUILD_WEBSOCKET_HOST $BUILD_WEBSOCKET_HOST g"
find /usr/share/nginx/html -name '*.js' -not -path "./packages/*" -not -path "./lib/*" | xargs sed -i "s BUILD_PLATFORM_VERSION $BUILD_PLATFORM_VERSION g"

echo 'replace complete!'
